#ifndef __CarMonitor_H
#define __CarMonitor_H


#ifdef __cplusplus
extern "C" {
#endif 

#include "gd32e10x.h"


typedef struct
{
	//监控L610采集变量相关
	uint8_t InputSta;
	uint8_t IN0_7;
	uint16_t InputAB;
	uint16_t AD5; //cpu ADC1
	uint16_t AD6; //cpu ADC0
	uint16_t AD7; //cpu ADC2
	
	uint16_t askInputDlySec;		//主动查询状态变量的延时
	
	//低电压时关闭L610功能，也关闭了定位
	uint32_t PowerADCSum;		//采样10次求平均
	uint32_t PowerADCCnt;		//采样次数
	uint32_t PowerADCAvg;		//平均值
	uint8_t LowPowerSta;		//低电压时=1，正常电压时=0
	
	uint8_t PowerOffSta;		//断电时=1，正常电压时=0
	uint8_t RcvCANInterupt;	//收到了1次CAN数据
	
	//车身状态，变化即上报
	//01
	//车门状态
	uint8_t u8AutoDoorSt;
	//车灯状态
	uint8_t u8AutoLigSt; 
	//附灯状态
	uint8_t u8AutoLedSt;
	//仪表背光亮度
	uint8_t u8BackLight; 
	//车窗状态
	uint8_t u8AutoWinSt; 
	//车锁状态
	uint8_t u8AutoLockSt; 
	//刹车和档位状态
	uint8_t u8AutoGearSt; 
	//点火启动信号
	uint8_t u8AutoIgSt;
	//充电状态
	uint8_t u8ChargeSt; 
	//安全带状态
	uint8_t u8SaftBtSt; 
	//里程
	uint32_t u32AutoOdo;
	//油量
	uint16_t u16AutoFuel;
	//电量
	uint16_t u16AutoSOC;
	//续航
	uint16_t u16SocForMile;
	//车速
	uint16_t u16AutoSpeed;
	//发动机转速
	uint16_t u16AutoEngRd;
	//提醒位
	uint8_t u8AutoRemindRD;
	//电池电压
	uint32_t u32AutoBATVol;
	//车辆电压
	uint32_t u32AutoVol;
	//油耗相关
	uint32_t u32AvgOilCsp;
	//大气压力
	uint32_t u32AtmoPress;
	//冷却液温度
	uint32_t u32CoolTemp;
	//节气门位置
	uint8_t u8ThroPos;
	//方向盘转角
	uint16_t u16WheelDeg;	
	//继电器供电断电
	uint8_t RelayCtrlSta;
	//bit1：1 空调AC开；0关
	u8 air_condition;
	//1空调风扇开；0关
	u8 air_fan;
	
	u8 air_fan_level;	//空调风扇档位  比如车辆有4挡，则值为0~4
	u8 throttle_open;	//油门踏板开度 0~100，百分比
	
	
	
	//A1 VIN
	uint8_t u8GetVINCarry[18];
	
	//A4
	//uint32_t u32AutoOdo;
	//uint16_t u16AutoFuel;
	//uint16_t u16SocForMile;
	
	//A5
//	u32 DTCLIST[10];
//	
//	//A7
//	u8 getPIDList[600];
	
	//AB
	//静态电压
	u32 u32static_v;
	//启动电压
	u32 u32launch_v;
	//节气门信号电压
	u32 u32thr_s_v;
	//油门踏板位置传感器电压
	u32 u32pedal_s_v;
	//喷油脉宽
	u32 u32inject_p_w;
	//喷油量
	u32 u32inject_p_q;  
	//喷油嘴时间
	u32 u32inject_p_t;
		
	//供油压力
	u32 u32oil_s_p;
	//进气压力
	u32 u32air_in_p;
	//进气温度
	u32 u32air_in_t;
	//水温
	u32 u32water_t;
	//前氧传感器电压
	u32 u32f_o_v;
	//后氧传感器电压
	u32 u32b_o_v;
	//汽车胎压
	u32 u32_auto_pressure;
	//汽车胎温
	u32 u32_auto_temp;
}CarMonitor_typedef;

extern CarMonitor_typedef	tagCarMon;

//这样定义为了节省CAN中断执行时间
#define RcvCANInterupt() 	tagCarMon.RcvCANInterupt = 1





void initCarMonitor(void);
uint16_t getL610IO_Input(uint8_t inNum, uint8_t mustNew);
void carMonitorSecDeal(void);
uint32_t askL610CarIOStatues(void);
void parseCarIO(uint8_t * pDa, uint16_t len);
uint32_t askCarInf(uint8_t * pDa, uint16_t len);
uint32_t answerCarInf_VIN(void);
uint32_t answerGDVersion(uint8_t type);
uint32_t answerCarInf(void);
uint32_t answerCarInf_mile(void);
uint32_t answerCarInf_errorList(uint8_t da);
uint32_t answerCarInf_PIDList(uint8_t da);
uint32_t answerCarInf_EnableList(void);
uint32_t answerCarInf_mend(uint8_t da);
uint8_t getLowPowerSta(void);
uint8_t getPowerOffSta(void);
uint32_t getCurrentVolt(void);
void carVoltageMonitor(void);
void deal_active_push_msg(void);
uint32_t PushDataFlowToL610(void);
uint32_t PushDTCSaveDataToL610(void);
uint32_t answerpkekey(void);
uint8_t engine_key_rd(void);
uint32_t answerstartpower(uint16_t code);

uint32_t set_car_Health(uint8_t* da , uint8_t len);//保存车辆保养信息
void reported_car_Health(void);//上报车辆保养健康信息
void reported_car_bms(void); //桂林公交BMS

uint32_t answer_fault_code_information_send(uint8_t da);
void vehicle_safety_seed_report( uint8_t *data );
void snwrv_data_msg_send( void );
#if( ADAS_COM_FUNCTION_DEF == 1 )
uint8_t adas_search_info_function( uint8_t *data, uint8_t cmd );
void adas_send_info_function( void );
#endif
#if( MCU_SAVE_DATA_ENABLE == 0 )
void mcu_save_data_st_set( uint8_t st );
uint8_t mcu_save_data_st_get( void );
void mcu_form_cpu_data_request( void );
#endif
#ifdef __cplusplus
}
#endif


#endif



